﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace Project3
{
    public abstract class Functions
    {
        public static Vector3 RandomUnitVector(PhibesGame game)
        {
            Vector3 v = new Vector3(game.Rand(200) - 100, game.Rand(200) - 100, game.Rand(200) - 100);
            v.Normalize();
            return v;
        }
        public static Vector3 FromAzimuth(float azimuth)
        {
            return new Vector3((float)Math.Sin(azimuth), 0, (float)Math.Cos(azimuth));
        }

        // poor man's collision detection (euclidean distance)
        public static List<Collidable> FindCollisions(Ship flyer, Bullet bullet, ObjectField asteroids)
        {
            List<Collidable> collisions = new List<Collidable>();
            foreach (ObjectField.Asteroid asteroid in asteroids.Asteroids)
            {
                if (!flyer.Destroyed && flyer.CollidesWith(asteroid))
                {
                    if(!collisions.Contains(flyer))
                        collisions.Add(flyer);
                    if(!collisions.Contains(asteroid))
                        collisions.Add(asteroid);
                }

                foreach (Bullet.Shell shell in bullet.Shells)
                {
                    if (shell.CollidesWith(asteroid))
                    {
                        if (!collisions.Contains(asteroid))
                            collisions.Add(asteroid);
                        if (!collisions.Contains(shell))
                            collisions.Add(shell);
                    }
                }
            }

            return collisions;
        }
    }
}
